package com.eaoa.uc.document.action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.lang.StringUtils;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.eaoa.base.EABaseAction;
import com.eaoa.query.pub.PubDocumentQuery;
import com.eaoa.uc.document.form.PubdocumentSearchCondition;
import com.eaoa.uc.document.form.PubdocumentSearchForm;


public class PubDocumentManageSearchAction extends EABaseAction {

	protected ActionForward doWork(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {

		PubdocumentSearchForm sform = (PubdocumentSearchForm) form;
		sform.initConditionPost();
		PubdocumentSearchCondition condition = (PubdocumentSearchCondition) sform
				.getCondition();

		PubDocumentQuery query = new PubDocumentQuery();
		
		if(StringUtils.isNotBlank(condition.getDocumentno()))
			query.setDocumentno(new Long(condition.getDocumentno()));
		
		query.setTitle(condition.getTitle());
		query.setDocumenttype(condition.getDocumenttype());
		query.setCreatedate(condition.getCreatedatefrom(), condition.getCreatedateto());
		query.setModuleno(condition.getModuleno());
		query.setTopModule(condition.getTopmodule());
		query.fetchModule();
		query.setPageRange(sform.getPageinfo());

		query.execute();
		request.setAttribute("results", query.getResults());

		return mapping.findForward("success");

	}
}
